<%--
 *  File:    OrgSelectPop.jsp
 *  @Author: Kevinfan
 *  Date:    4/11/2011
 *
 *  Copyright (C) 2000 - 2012 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>


<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>

<%
  //init param
  Category cat = Category.getInstance("jsp.OrgSelectPop");  
  String strModuleName = "TDR";
  String strTableName = "ovorgsummary";
  Integer sourceorgid = new Integer(-1);
  String contextPath = request.getContextPath();
%>
  

<%@ include file="/inc/PageDefault.inc" %>
<html>
<head>
<title>Add</title>
<PageFlow:CheckPageFlow pageName="p_orgselectpop"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=contextPath%>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%=contextPath%>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/FuncLib.js"></script>
<%@ include file="/inc/SummaryDivision.inc" %>
<%
  cat.debug("The strCurSearchName is :" + strCurSearchName);
  cat.debug("The strCurSearchValue is :" + strCurSearchValue);  
  cat.debug("The strCurOrderByCol is :" + strCurOrderByCol);
  cat.debug("The strCurOrderByType is :" + strCurOrderByType);
  cat.debug("The nCurMaxItem is :" + nCurMaxItem);  
  cat.debug("The nCurCount is :" + nCurCount);  
  cat.debug("The nCurPageNo is :" + nCurPageNo);
  cat.debug("The nCurTotalPage is :" + nCurTotalPage);
  cat.debug("The nCurEndIndex is :" + nCurEndIndex);
  cat.debug("The bCurHasPre is :" + bCurHasPre);
  cat.debug("The bCurHasNext is :" + bCurHasNext);

  String MCorgcode=(request.getParameter("MCorgcode")==null)?"":(request.getParameter("MCorgcode"));
  
  Vector orgs = (Vector)pageContext.getAttribute("orgsummary");
  if(orgs == null)
  {
    orgs = new Vector();
  }
  cat.debug("The orgs is :" + orgs);          
%>

<script language="JavaScript">

function clickItem(id, name,code, shortname)
{
  document.frm.selectorgid.value = id;
  document.frm.orgname.value = name;
  document.frm.orgcode.value = code;
  document.frm.selectshortname.value = shortname;
  parent.setOrg(document.frm.selectorgid.value,document.frm.orgname.value,document.frm.orgcode.value);
  parent.hiddenFrm();
}

function page_summary(actionvalue,orderbyname)
{
  var editform = summaryPrepare(frm,actionvalue,orderbyname);
  editform.action = "OrgSelectPop.jsp?maxitem=8&<%= OvalTools.randomURL() %>&selectoption=<%=JspHelper.filterNull( request.getParameter("selectoption") )%>&strglobalpccodes=<%=JspHelper.filterNull( request.getParameter("strglobalpccodes") )%>";
  editform.target = "_self";
  isRunning = true;
  editform.submit();
}

function page_setOrgValue()
{    
      parent.setOrg(document.frm.selectorgid.value,document.frm.orgname.value,document.frm.orgcode.value);
      parent.hiddenFrm();
}
function setError()
{
   alert("<%=message.getMessage("No_Correct_Company")%>");
   if (document.frm.selectoption.value == "notintree" || document.frm.selectoption.value == "intree")
      opener.setClean2();
   else
      opener.setClean();
   window.close();
}
</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<form name="frm" method="post">
<table width="100%" cellspacing="0" cellpadding="0" height="100%">
    <input type="hidden" name="pagename" value="p_orgselectpop">
    <input type="hidden" name="actionname">
    <custom:hidden property="orgstatus"/>
    <custom:hidden property="orgids"/> 
    <custom:hidden property="itemid"/>
    <custom:hidden property="flag"/>
    <custom:hidden property="strglobalpccodes" />
    <custom:hidden property="regioncode" />
    <custom:hidden property="citycode" />
    <custom:hidden property="orgglobalpccode"/>
    <custom:hidden property="marketingplandetailid"/>
    <custom:hidden property="orgglobalpccodes"/>
	<custom:hidden property="relationid"/>
	<custom:hidden property="partnertype"/>
	<custom:hidden property="exclusivepccode"/>
	<custom:hidden property="exclusiveorgid"/>
	<custom:hidden property="globalpccode"/>
	<custom:hidden property="noglobalpccodestr"/>
	<input type="hidden" name="sourceorgid" value="<%=JspHelper.filterNull(pageContext.getAttribute("sourceorgid"))%>">
    <input type="hidden" name="selectoption" value="<%=JspHelper.filterNull( request.getParameter("selectoption") )%>">
    <input type="hidden" name="MCorgcode" value="<%=JspHelper.filterNull(MCorgcode)%>">
    <input type="hidden" name="orgid" value="<%=JspHelper.filterNull( pageContext.getAttribute("orgid") )%>">
    <input type="hidden" name="isBuyer"  value="<%=JspHelper.filterNull(request.getParameter("isBuyer"))%>">
    <tr>
      <td valign="top">
        <table width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="summary_top"></td>
          </tr>
        </table>
        <table width="100%" cellspacing="0" cellpadding="0">
         <%@ include file="/inc/SummarySearch.inc" %>
        </table> 
      <table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
	  <%
	         String orgCode = label.getLabelName("L_OrgCode");
		 String orgName = label.getLabelName("L_OrgName");
		 if (request.getParameter("selectoption") != null) 
		 {
			 if (request.getParameter("selectoption").equals("supplier"))
			 {
			     orgCode = label.getLabelName("L_SupplierCode");
		             orgName = label.getLabelName("L_SupplierName");
			 } 
			 else if (request.getParameter("selectoption").equals("distributor"))
			 {
			     orgCode = label.getLabelName("L_DistributorCode");
		             orgName = label.getLabelName("L_DistributorName");
			 }else if (request.getParameter("selectoption").equals("xjpcustomer"))
			 {
			     orgCode = label.getLabelName("L_CustomerCode");
		             orgName = label.getLabelName("L_CustomerName");
			 }


		 }
	  %>
	  <tr class="deepblue-left">
      <td class="title_center" width="1%">&nbsp;</td>
      <td class="title_center" width="25%">&nbsp;<a href="javascript:page_summary('orderby','orgcode')"><%=JspHelper.filterNull(orgCode)%></a></td>
      <td class="title_center" width="49%">&nbsp;<a href="javascript:page_summary('orderby','orgname')"><%=JspHelper.filterNull(orgName)%></a></td>
     </tr>

     <%
        int i = 0;
        String strIsChecked = new String("Checked");
        String strClassType = new String();   
        Integer nOrgId = null;
        String strOrgName = "";    
        String strOrgCode = ""; 
	      String strOrgShortName = "";	
     %>
     <logic:iterate id="org" collection="<%= orgs %>">                      
      
     <%
       HashMap orgMap = (HashMap)pageContext.getAttribute("org"); 
       if(i%2 == 1)
       {
         strClassType = "td-listrom";
       }else{                    
         strClassType = "";
       }
       if(i != 0)
       {          
         strIsChecked = "";
       }
       else
       {
         nOrgId = (Integer)(orgMap.get("orgid"));
         strOrgName = (String)(orgMap.get("orgname"));  
         strOrgCode = (String)(orgMap.get("orgcode"));  
	 strOrgShortName = (String)(orgMap.get("shortname"));
       }  
              
       i++;        
     %>   
     <tr onmouseover="this.className='tr-over'" 
         onmouseout="this.className='<%=JspHelper.filterNull(strClassType)%>'"
         class="<%=JspHelper.filterNull(strClassType)%>"  
         onClick="javascript:radiotrue('selectItem<%=JspHelper.filterNull( i )%>'); 
                             clickItem('<%=JspHelper.filterNull( orgMap.get("orgid") )%>', '<%= OvalTools.replaceQuot(orgMap.get("orgname")) %>','<%= OvalTools.replaceQuot(orgMap.get("orgcode")) %>', '<%=OvalTools.replaceQuot(orgMap.get("shortname"))%>')">    
      <td> 
        <input id="selectItem<%=JspHelper.filterNull( i )%>" type="radio" name="selectOrg" class="normalradio"
               value="<%=JspHelper.filterNull( orgMap.get("orgid") )%>" <%=JspHelper.filterNull( strIsChecked )%>   onClick="javascript:clickItem('<%=JspHelper.filterNull(orgMap.get("orgid"))%>','<%=OvalTools.replaceQuot(orgMap.get("orgname"))%>', '<%= OvalTools.replaceQuot(orgMap.get("orgcode"))%>', '<%=OvalTools.replaceQuot(orgMap.get("shortname"))%>')">
      </td>
      <td class="<%=JspHelper.filterNull( strClassType )%>">&nbsp;<%=JspHelper.filterNull( orgMap.get("orgcode") )%></td>
      <td class="<%=JspHelper.filterNull( strClassType )%>">&nbsp;<%=JspHelper.filterNull( orgMap.get("orgname") )%></td>
     </tr>
    </logic:iterate> 
    <input type="hidden" name="selectorgid" value="<%=JspHelper.filterNull( nOrgId )%>">
    <input type="hidden" name="orgname" value="<%=JspHelper.filterNull( strOrgName )%>">  
    <input type="hidden" name="orgcode" value="<%=JspHelper.filterNull( strOrgCode )%>">  
    <input type="hidden" name="selectshortname" value="<%=JspHelper.filterNull( strOrgShortName)%>">  
         <%@ include file="/inc/SummaryActionPop.inc" %>
      </table>
      </td>
    </tr>
</table>
</form>
<%
	if (orgs.size() == 1) {
%>
<script>page_setOrgValue();</script>
<%	} else if (orgs.size() == 0) { %>
<script>setError();</script>
<%	} %>
</body>
</html>


